﻿using Bear.Library.Util;
using Bear.Library.WinApi;
using Bear.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Bear.BLL
{

    public abstract class ScriptBase
    {
        public delegate void MessageDelegate(string message, params object[] objs);
        public event MessageDelegate ShowMessage;
        public abstract void Run(DataCenter dc);

        protected virtual void OnShowMessage(string message, params object[] objs)
        {
            if (this.ShowMessage != null)
                this.ShowMessage(message, objs);
        }

        //protected virtual void 显示说明(string message, params object[] objs)
        //{
        //    if (this.ShowMessage != null)
        //        this.ShowMessage(message, objs);
        //}

        //protected void 延时(int millisecond)
        //{
        //    Thread.Sleep(millisecond);
        //}

        //protected void 鼠标移动(int x, int y)
        //{
        //    KeyboardMouseOperator.MouseMove(new Point(x, y));
        //}

        //protected void 键盘按键(Keys key)
        //{
        //    KeyboardMouseOperator.KeyPress(key);
        //}

        //protected string 启动程序(string path)
        //{
        //    ProcessStartInfo startInfo = new ProcessStartInfo(path)
        //    {
        //        WorkingDirectory = Path.GetDirectoryName(path)
        //    };
        //    Process process = Process.Start(startInfo);
        //    process.WaitForInputIdle();

        //    return process.MainWindowTitle;
        //}

        //protected IntPtr 获取窗口标识(string title)
        //{
        //    return WinApiHelper.FindWindow(null, title);
        //}
        //protected IntPtr 获取按钮(IntPtr windowhandle, string title)
        //{
        //    return WinApiHelper.FindWindowEx(windowhandle, IntPtr.Zero, null, title);
        //}

        //protected void 鼠标左键单击()
        //{
        //    KeyboardMouseOperator.MouseClick(true);
        //}

        //protected void 鼠标左键双击()
        //{
        //    KeyboardMouseOperator.MouseDoubleClick();
        //}


        //protected void 鼠标右键单击()
        //{
        //    KeyboardMouseOperator.MouseClick(false);
        //}

        //protected 点 获取按钮位置(IntPtr handle)
        //{

        //    点 point = new 点();
        //    var rect = new Bear.Library.WinApi.Rect();
        //    WinApiHelper.GetWindowRect(handle, ref rect);

        //    point.X = rect.Left + (rect.Right - rect.Left) / 2;
        //    point.Y = rect.Top + (rect.Bottom - rect.Top) / 2;

        //    return point;
        //}

        //protected 矩形 获取窗口大小(IntPtr handle)
        //{
        //    var rect = new Bear.Library.WinApi.Rect();
        //    WinApiHelper.GetWindowRect(handle, ref rect);

        //    return new 矩形()
        //    {
        //        左边距 = rect.Left,
        //        上边距 = rect.Top,
        //        宽 = rect.Right - rect.Left,
        //        长 = rect.Bottom - rect.Top,
        //        边框宽度 = (rect.Right - rect.Left - 800) / 2,
        //        标题栏宽度 = rect.Bottom - rect.Top - 600 - ((rect.Right - rect.Left - 800) / 2)
        //    };
        //}

        //protected Bitmap 获取窗口图片(IntPtr handle)
        //{
        //    return ScreenCapturer.Capture(handle);
        //}

        //protected void 输入字符(string message)
        //{
        //    KeyboardMouseOperator.InputString(message);
        //}

        //protected 点 图片位置(Bitmap source, string targetPath, double similarity)
        //{
        //    using (Image temp = Bitmap.FromFile(targetPath))
        //    {
        //        List<Point> lst = CvHelper.TemplateMatching(source, (Bitmap)temp, similarity);

        //        return new 点()
        //        {
        //            X = lst.FirstOrDefault().X,
        //            Y = lst.FirstOrDefault().Y,
        //        };
        //    }
        //}




        //public string[] CompilerOutput { get; set; }
    }
}
